package cn.chinaflame.pagodas.service;

import cn.chinaflame.pagodas.Result.Result;
import cn.chinaflame.pagodas.constant.Sysconst;
import cn.chinaflame.pagodas.dto.*;
import cn.chinaflame.pagodas.entity.PaGreetings;
import cn.chinaflame.pagodas.entity.PaProduct;
import cn.chinaflame.pagodas.entity.PaProductDetail;
import cn.chinaflame.pagodas.enums.CodeEnum;
import cn.chinaflame.pagodas.repository.PaGreetingsRepository;
import cn.chinaflame.pagodas.repository.PaProductDetailRepository;
import cn.chinaflame.pagodas.repository.PaProductRepository;
import cn.chinaflame.pagodas.req.ProductQryReq;
import cn.chinaflame.pagodas.req.ProductReq;
import cn.chinaflame.pagodas.utils.DateTimes;
import cn.chinaflame.pagodas.utils.ParamPreconditions;
import static cn.chinaflame.pagodas.constant.Sysconst.FLOORINSTEADAREA;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wwt
 * @date 2018年1月4日 下午6:00:37
 */
@Service
public class PaProductService {
    private final static Logger log = LoggerFactory.getLogger(PaProductService.class);
    @Autowired
    private PaProductRepository paProductRepository;
    @Autowired
    private IdGeneratorService idGeneratorService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private YwProductTypeService ywProductTypeService;
    @Autowired
    private YwItemService ywItemService;
    @Autowired
    private PaProductPositionService paProductPositionService;
    @Autowired
    private PaProductAreaService PaProductAreaService;
    @Autowired
    private PaProductDetailRepository paProductDetailRepository;
    @Autowired
    private PaProductDetailService paProductDetailService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PaProductPointService paProductPointService;
    @Autowired
    private PaGreetingsRepository paGreetingsRepository;


    @Transactional
    public PaProductDto add(ProductReq req) {
        log.info("商品添加【service】req:{}", req);
        ParamPreconditions.checkNotEmpty(req.getItemId(), CodeEnum.FAIL.getCode(), "项目id不能为空");
        PaProduct yproduct = new PaProduct();
        yproduct.setId(idGeneratorService.generateIdByTableName("yw_product"));
        yproduct.setName(req.getName());
        yproduct.setProductTypeId(req.getProductTypeId());
        //获取商品类别名称
        List<ProductTypeDto> ProductType = ywProductTypeService.query(null, null, req.getProductTypeId(), null, null, null);
        yproduct.setProductTypeName(ProductType.get(0).getName());
        yproduct.setItemId(req.getItemId());
        //获取商品所属项目名称
        ItemDto Item = ywItemService.querybyId(req.getItemId());
        yproduct.setItemName(Item.getName());
        yproduct.setPositionId(req.getPositionId());
        //获取商品所在位置名称
        List<PaProductPositionDto> ProductPositionDto = paProductPositionService.queryList(null, null, req.getPositionId(), null, null).getData();
        yproduct.setPositionName(ProductPositionDto.get(0).getName());
        yproduct.setAreaId(ProductPositionDto.get(0).getAreaId());
        //获取商品所在区域名称
        List<PaProductAreaDto> ProductAreaDto = PaProductAreaService.queryList(null, null, ProductPositionDto.get(0).getAreaId(), null).getData();
        yproduct.setAreaName(ProductAreaDto.get(0).getName());
        yproduct.setNumber(req.getNumber());
        List<Map<String, Object>> map = req.getTermList();
        for (int i = 0; i < map.size(); i++) {
            PaProductDetail ppd = new PaProductDetail();
            ppd.setId(idGeneratorService.generateIdByTableName("yw_product_detail"));
            ppd.setPrice(new BigDecimal((String) map.get(i).get("termPrice")));
            ppd.setProductId(yproduct.getId());
            ppd.setTerm(Integer.valueOf((String) map.get(i).get("termDes")));
            paProductDetailRepository.save(ppd);
        }
        yproduct.setPrice(new BigDecimal((String) map.get(0).get("termPrice")));
        yproduct.setState(Sysconst.ENABLED_TRUE);                        //使用状态：0-启用；1-弃用

        yproduct.setCreatetime(DateTimes.nowDateTime());
        yproduct.setUpdatetime(DateTimes.nowDateTime());
        paProductRepository.saveAndFlush(yproduct);
        PaProductDto dto = new PaProductDto();
        BeanUtils.copyProperties(yproduct, dto);
        return dto;
    }

    /*new_edition发布商品接口，新方法*/

    /**
     * 发布商品
     *
     * @param req
     * @return
     */
    @Transactional
    public PaProductDto add1(ProductReq req) {
        log.info("商品添加【service】req:{}", req);
        ParamPreconditions.checkNotEmpty(req.getItemId(), CodeEnum.FAIL.getCode(), "项目id不能为空");
        PaProduct yproduct = new PaProduct();
        yproduct.setId(idGeneratorService.generateIdByTableName("yw_product"));
        yproduct.setName(req.getName());
        yproduct.setProductTypeId(req.getProductTypeId());
        //获取商品类别名称
        List<ProductTypeDto> ProductType = ywProductTypeService.query(null, null, req.getProductTypeId(), null, null, null);
        yproduct.setProductTypeName(ProductType.get(0).getName());
        yproduct.setItemId(req.getItemId());
        //获取商品所属项目名称
        ItemDto Item = ywItemService.querybyId(req.getItemId());
        yproduct.setItemName(Item.getName());
        yproduct.setPositionId(req.getPositionId());
        yproduct.setGreetingsId(req.getGreetingsId());
//		//获取商品所在位置名称
//		List<PaProductPositionDto> ProductPositionDto = paProductPositionService.queryList(null, null, req.getPositionId(), null, null).getData();
//		yproduct.setPositionName(ProductPositionDto.get(0).getName());
//		yproduct.setAreaId(ProductPositionDto.get(0).getAreaId());
//		//获取商品所在区域名称
//		List<PaProductAreaDto> ProductAreaDto = PaProductAreaService.queryList(null, null, ProductPositionDto.get(0).getAreaId(), null).getData();
//		yproduct.setAreaName(ProductAreaDto.get(0).getName());		
//		yproduct.setNumber(req.getNumber());

        /*区域、位置、行列处理*/
//		String[] positionIdAry = req.getPositionIds().split(",");
//		String[] pointIdAry = null;
//		List<Map<String, String>> pointList = Lists.newArrayList();
//		if(!Strings.isNullOrEmpty(req.getPointIds())) {
//			pointIdAry = req.getPointIds().split(";");
//			for(int i=0;i<pointIdAry.length;i++) {
//				if(Strings.isNullOrEmpty(pointIdAry[i]))
//					pointList.add(null);
//				String[] rows = pointIdAry[i].split(",");
//				if(rows == null || rows.length == 0)
//					pointList.add(null);
//				for(int j=0;j<rows.length;j++) {
//					String start = rows[j].substring(0, 2);
//					String end = rows[j].substring(2);
//					Map<String, String> en = Maps.newHashMap();
//					en.put("start", start);
//					en.put("end", end);
//					pointList.add(en);
//				}
//			}
//		}
        //因为商品流程改动，添加商品暂不需要位置信息
//        int stock = paProductPointService.getStock2(req.getPositionIds());
//        ParamPreconditions.checkArgument(stock > 0, CodeEnum.FAIL.getCode(), "位置不足");
//        String[] positionIdAry = req.getPositionIds().split(",");
//        String findSql = "select count(1) from pa_product where state = 0 and FIND_IN_SET(?,position_ids) > 0";
//        for(int i=0;i<positionIdAry.length;i++){
//        	Integer count = jdbcTemplate.queryForObject(findSql, Integer.class,positionIdAry[i]);
//        	ParamPreconditions.checkArgument(count == null || count == 0, CodeEnum.FAIL.getCode(), "位置已被占用");
//        }
//        yproduct.setPositionIds(req.getPositionIds());



        List<Map<String, Object>> map = req.getTermList();
        for (int i = 0; i < map.size(); i++) {
            PaProductDetail ppd = new PaProductDetail();
            ppd.setId(idGeneratorService.generateIdByTableName("yw_product_detail"));
            ppd.setPrice(new BigDecimal((String) map.get(i).get("termPrice")));
            ppd.setProductId(yproduct.getId());
            ppd.setTerm(Integer.valueOf((String) map.get(i).get("termDes")));
            paProductDetailRepository.save(ppd);
        }
        yproduct.setPrice(new BigDecimal((String) map.get(0).get("termPrice")));
        yproduct.setState(Sysconst.ENABLED_TRUE);                        //使用状态：0-启用；1-弃用
        yproduct.setDescription(req.getDescription());
        yproduct.setPraying(req.getPraying());
        yproduct.setSubCommodity(req.getSubCommodity());
        yproduct.setCommodityType(req.getCommodityType());
        yproduct.setFacialPhoto(req.getFacialPhoto());
        yproduct.setCertificatePhoto(req.getCertificatePhoto());
        yproduct.setCreatetime(DateTimes.nowDateTime());
        yproduct.setUpdatetime(DateTimes.nowDateTime());
        paProductRepository.saveAndFlush(yproduct);
        PaProductDto dto = new PaProductDto();
        BeanUtils.copyProperties(yproduct, dto);
        return dto;
    }

    public PaProductDto update(ProductReq req) {
        log.info("商品修改【service】req:{}", req);
        ParamPreconditions.checkNotEmpty(req.getId(), CodeEnum.FAIL.getCode(), "商品id不能为空");
        PaProduct yproduct = new PaProduct();
        BeanUtils.copyProperties(req, yproduct);
        yproduct.setUpdatetime(DateTimes.nowDateTime());
        //获取商品类别名称
        List<ProductTypeDto> ProductType = ywProductTypeService.query(null, null, req.getProductTypeId(), null, null, null);
        yproduct.setProductTypeName(ProductType.get(0).getName());
        //获取商品所属项目名称
        ItemDto Item = ywItemService.querybyId(req.getItemId());
        yproduct.setItemName(Item.getName());
        //获取商品所在位置名称
        List<PaProductPositionDto> ProductPositionDto = paProductPositionService.queryList(null, null, req.getPositionId(), null, null).getData();
        yproduct.setPositionName(ProductPositionDto.get(0).getName());
        //获取商品所在区域名称
        List<PaProductAreaDto> ProductAreaDto = PaProductAreaService.queryList(null, null, ProductPositionDto.get(0).getAreaId(), null).getData();
        yproduct.setAreaName(ProductAreaDto.get(0).getName());
        List<PaProductDetail> ppdlist = paProductDetailService.queryList(null, null, null, req.getId());
        for (int i = 0; i < ppdlist.size(); i++) {
            paProductDetailRepository.delete(ppdlist.get(i).getId());
        }
        List<Map<String, Object>> map = req.getTermList();
        for (int i = 0; i < map.size(); i++) {
            PaProductDetail ppd = new PaProductDetail();
            ppd.setId(idGeneratorService.generateIdByTableName("yw_product_detail"));
            ppd.setPrice(new BigDecimal((String) map.get(i).get("termPrice")));
            ppd.setProductId(yproduct.getId());
            ppd.setTerm(Integer.valueOf((String) map.get(i).get("termDes")));

            paProductDetailRepository.save(ppd);
        }
        yproduct.setPrice(new BigDecimal((String) map.get(0).get("termPrice")));
        yproduct = paProductRepository.saveAndFlush(yproduct);
        PaProductDto dto = new PaProductDto();
        BeanUtils.copyProperties(yproduct, dto);
        return dto;
    }

    public boolean delete(String id) {
        log.info("商品删除【service】id:{}", id);
        ParamPreconditions.checkNotEmpty(id, CodeEnum.FAIL.getCode(), "入参为空");
        PaProduct product = paProductRepository.findOne(id);
        if (product == null) return true;
        product.setState(Sysconst.ENABLED_FALSE);
        paProductRepository.saveAndFlush(product);
        return true;
    }


    /**
     * 商品查询全部
     *
     * @param pageIndex     页码
     * @param pageSize      页数
     * @param itemId        项目ID
     * @param productTypeId 商品类别
     * @param areaId        商品区域
     * @param positionId    商品位置
     * @return
     */
    public List<PaProductDto> query(Integer pageIndex, Integer pageSize, String itemId, String productTypeId, String areaId,
                                    String positionId, String id, String state, String addTime, String shelfTime,String commodityType) {
        log.info("商品查询【service】pageIndex:{}, pageSize:{}, itemId:{}, productTypeId:{}, areaId:{}, positionId:{}, id:{}, state:{}, "
                        + "addTime:{}, shelfTime:{}",
                pageIndex, pageSize, itemId, productTypeId, areaId, positionId, id, state, addTime, shelfTime);

        if (commonService.paginationSupport(pageIndex, pageSize)) {
            return queryByPage(pageIndex, pageSize, itemId, productTypeId, areaId, positionId, id, state, addTime, shelfTime);
        }
        List<PaProduct> productlist = paProductRepository.findAll(new Specification<PaProduct>() {
            @Override
            public Predicate toPredicate(Root<PaProduct> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> list = Lists.newArrayList();
                if (null == state || "".equals(state)) {
                    list.add(cb.equal(root.get("state").as(String.class), Sysconst.ENABLED_TRUE));
                } else {
                    list.add(cb.equal(root.get("state").as(String.class), Sysconst.ENABLED_FALSE));
                }
                if (!Strings.isNullOrEmpty(itemId)) {
                    list.add(cb.equal(root.get("itemId").as(String.class), itemId));
                }
                if (!Strings.isNullOrEmpty(productTypeId)) {
                    list.add(cb.equal(root.get("productTypeId").as(String.class), productTypeId));
                }
                if (!Strings.isNullOrEmpty(areaId)) {
                    list.add(cb.equal(root.get("areaId").as(String.class), areaId));
                }
                if (!Strings.isNullOrEmpty(positionId)) {
                    list.add(cb.equal(root.get("positionId").as(String.class), positionId));
                }
                if (!Strings.isNullOrEmpty(id)) {
                    list.add(cb.equal(root.get("id").as(String.class), id));
                }
                if (!Strings.isNullOrEmpty(addTime)) {
                    list.add(cb.like(root.get("addTime").as(String.class), "%" + shelfTime + "%"));
                }
                if (!Strings.isNullOrEmpty(shelfTime)) {
                    list.add(cb.like(root.get("shelfTime").as(String.class), "%" + shelfTime + "%"));
                }
                if (!Strings.isNullOrEmpty(commodityType)) {
                    list.add(cb.equal(root.get("commodityType").as(String.class),commodityType));
                }
                Predicate[] p = new Predicate[list.size()];
                return cb.and(list.toArray(p));
            }
        });
        List<PaProductDto> dtoList = Lists.newArrayList();
        for (PaProduct item : productlist) {
            PaProductDto dto = new PaProductDto();
            BeanUtils.copyProperties(item, dto);
            /*new_edition 添加区域位置信息，多个以，分割*/
            //商品流程变动，商品位置信息暂时不需要
//            String sql = "select GROUP_CONCAT(CONCAT(area.name,position.name)) from pa_product_area area,pa_product_position position where area.id = position.area_id and FIND_IN_SET(position.id,'" + item.getPositionIds() + "')";
//            String name = jdbcTemplate.queryForObject(sql, String.class);
//            List<String> names = Arrays.asList(name.split(","));
//            List<String> newnames = Lists.newArrayList();
//            for(String n:names) {
//            	StringBuffer nn = new StringBuffer();
//            	if(StringUtils.isNotBlank(n) && n.length() == 6) {
//            		nn.append(Integer.parseInt(n.substring(0,2)));
//            		nn.append(FLOORINSTEADAREA);
//            		nn.append(Integer.parseInt(n.substring(3,5)));
//            		nn.append(n.substring(5));
//            		newnames.add(nn.toString());
//            	}
//            }
//            dto.setPositionIdsName(String.join(",", newnames));
            /**/
            List<PaProductDetail> list = paProductDetailService.queryList(null, null, null, item.getId());
            List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("termDes", list.get(i).getTerm());
                map.put("termPrice", list.get(i).getPrice());
                list2.add(map);
            }
            dto.setTermList(list2);
            if(dto.getGreetingsId() != null && dto.getGreetingsId().length() >0){
                String[] str = dto.getGreetingsId().split(",");
                String greetingsName = "";
                for(String greetingsId : str) {
                    PaGreetings paGreetings = paGreetingsRepository.findOne(Integer.valueOf(greetingsId));
                    greetingsName = greetingsName+paGreetings.getGreetings();
                    greetingsName = greetingsName+ ",";
                }
                dto.setGreetingsName(greetingsName.substring(0,greetingsName.length()-1));
            }

            dtoList.add(dto);
        }
        return dtoList;
    }

    /**
     * 商品查询全部
     *
     * @param pageIndex     页码
     * @param pageSize      页数
     * @param itemId        项目ID
     * @param productTypeId 商品类别
     * @param areaId        商品区域
     * @param positionId    商品位置
     * @return
     */
    public List<PaProductDto> queryByPage(Integer pageIndex, Integer pageSize, String itemId, String productTypeId, String areaId,
                                          String positionId, String id, String state, String addTime, String shelfTime) {
        log.info("商品查询【service】pageIndex:{}, pageSize:{}, itemId:{}, productTypeId:{}, areaId:{}, positionId:{}, id:{}, state:{},"
                        + "addTime:{}, shelfTime:{}",
                pageIndex, pageSize, itemId, productTypeId, areaId, positionId, id, state, addTime, shelfTime);
        Pageable p = new PageRequest(pageIndex - 1, pageSize, new Sort(Direction.DESC, "updatetime"));
        Page<PaProduct> entityList = paProductRepository.findAll(new Specification<PaProduct>() {
            @Override
            public Predicate toPredicate(Root<PaProduct> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> list = Lists.newArrayList();
                if (null == state || "".equals(state)) {
                    list.add(cb.equal(root.get("state").as(String.class), Sysconst.ENABLED_TRUE));
                } else {
                    list.add(cb.equal(root.get("state").as(String.class), Sysconst.ENABLED_FALSE));
                }
                if (!Strings.isNullOrEmpty(itemId)) {
                    list.add(cb.equal(root.get("itemId").as(String.class), itemId));
                }
                if (!Strings.isNullOrEmpty(productTypeId)) {
                    list.add(cb.equal(root.get("productTypeId").as(String.class), productTypeId));
                }
                if (!Strings.isNullOrEmpty(areaId)) {
                    list.add(cb.equal(root.get("areaId").as(String.class), areaId));
                }
                if (!Strings.isNullOrEmpty(positionId)) {
                    list.add(cb.equal(root.get("positionId").as(String.class), positionId));
                }
                if (!Strings.isNullOrEmpty(id)) {
                    list.add(cb.equal(root.get("id").as(String.class), id));
                }
                if (!Strings.isNullOrEmpty(addTime)) {
                    list.add(cb.like(root.get("addTime").as(String.class), "%" + shelfTime + "%"));
                }
                if (!Strings.isNullOrEmpty(shelfTime)) {
                    list.add(cb.like(root.get("shelfTime").as(String.class), "%" + shelfTime + "%"));
                }
                Predicate[] p = new Predicate[list.size()];
                return cb.and(list.toArray(p));
            }
        }, p);
        List<PaProduct> itemList = entityList.getContent();
        List<PaProductDto> dtoList = Lists.newArrayList();
        for (PaProduct item : itemList) {
            PaProductDto dto = new PaProductDto();
            BeanUtils.copyProperties(item, dto);
            List<PaProductDetail> list = paProductDetailService.queryList(null, null, null, item.getId());
            List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("termDes", list.get(i).getTerm());
                map.put("termPrice", list.get(i).getPrice());
                list2.add(map);
            }
            dto.setTermList(list2);
            dtoList.add(dto);
        }
        return dtoList;
    }

    public Result<List<PaProductDto>> queryByPageByJdbc(ProductQryReq req) {
        log.info("商品按区域分页查询【service】req:{}", req);

        String sql = "SELECT " +
                "p.id as id," +
                "p.name as name," +
                "p.product_type_id as productTypeId," +
                "p.product_type_name as productTypeName," +
                "p.item_id as itemId," +
                "p.item_name as itemName," +
                "p.area_id as areaId," +
                "p.area_name as areaName," +
                "p.position_id as positionId," +
                "p.position_name as positionName," +
                "p.number as number," +
                "p.price as price," +
                "p.state as state," +
                "p.day_one as dayOne," +
                "p.day_three as dayThree," +
                "p.day_week as dayWeek," +
                "p.day_month as dayMonth," +
                "p.day_quarter as dayQuarter," +
                "p.day_half_year as dayHalfYear," +
                "p.day_year as dayYear," +
                "p.createtime as createtime," +
                "p.updatetime as updatetime," +
                "p.cost_price as costPrice," +
                "p.add_time as addTime," +
                "p.shelf_time as shelfTime"
                + " FROM yw_item i, pa_product p where " +
                "i.id = p.item_id and i.state=0 and p.state=0";
        StringBuilder sb = new StringBuilder();
//		sb.append(" and i.agent_id in ("+str+")");
        if (!Strings.isNullOrEmpty(req.getItemId()))
            sb.append(" and i.id =").append(req.getItemId());
        if (!Strings.isNullOrEmpty(req.getProvinceCode()))
            sb.append(" and i.province_code =").append(req.getProvinceCode());
        if (!Strings.isNullOrEmpty(req.getCityCode()))
            sb.append(" AND i.city_code =").append(req.getCityCode());
        if (!Strings.isNullOrEmpty(req.getAreaCode()))
            sb.append(" AND i.area_code =").append(req.getAreaCode());
		/*if(!Strings.isNullOrEmpty(req.getAgentId())){
			sb.append(" AND i.agent_id =").append(req.getAgentId());
		}*/

        sb.append(" ORDER BY p.updatetime DESC");
        log.info(sql+sb.toString());
        JdbcPage<PaProductDto> page = new JdbcPage<>(sql + sb.toString(), req.getPageSize(), req.getPageIndex(), jdbcTemplate, PaProductDto.class);
//		List<PaProductDto> content = page.getPage();
//		String detailSql = "select GROUP_CONCAT(CONCAT(price,'/',term)) as priceDesc from pa_product_detail where product_id=?";
//		for(PaProductDto dto : content) {
//			String priceDes = jdbcTemplate.queryForObject(detailSql, String.class, dto.getId());
//		}
//        List<PaProductDto> dtos = page.getPage();

        return Result.createPage(page.getPage(), page.getCount());
    }

    public Object getGreetingsByID (String productId) {
        log.info("祝福语根据编号查询列表service productId:{}",productId);
        try{
            if ("".equals(productId) || productId == null) {
                return Result.create("FALSE","商品编号不能为空");
            }
            PaProduct paProduct = paProductRepository.findOne(productId);
            if (paProduct == null) {
                return Result.create("FALSE","未查询到该商品");
            } else if (paProduct.getGreetingsId() == null || "".equals(paProduct.getGreetingsId())) {
                return Result.create("FALSE","商品未绑定祝福语");
            }
            String[] str = paProduct.getGreetingsId().split(",");
            List<PaGreetings> list = Lists.newArrayList();
            for (String id : str){
                PaGreetings paGreetings = paGreetingsRepository.findOne(Integer.valueOf(id));
                if (paProduct == null) {
                    continue;
                }
                list.add(paGreetings);
            }
            return Result.create(list);
        }catch (Exception e){
            log.info("错误信息为：e{}",e);
        }
        return Result.create("FALSE","查询失败");
    }

}
